const mongoose = require('mongoose')

const userSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true,
    minlength: 2,
    maxlength: 20
  },
  email: {
    type: String,
    unique: true,
    required: true
  },
  password: {
    type: String,
    required: true
  },
  role: {
    type: String,
    required: true
  },
  state: {
    type: Number,
    default: 0
  }
})

const User = mongoose.model('User', userSchema);

// User.create({
//   username: 'itheima',
//   email: 'itheima@itcast.com',
//   password: '123456',
//   role: 'admin',
//   state: 0
// }).then((res) => {
//   console.log('用户创建成功');
//   console.log(res);
// }).catch(err => {
//   console.log('用户创建失败');
//   console.log(err);
// })

module.exports = {
  User
}